trait DependencyCore {
	trait Factory[+T] {
		def make: T
	}
	
	def make[T](implicit factory: Factory[T]): T = factory.make
}

trait MyDependencies extends DependencyCore {
  // an abstract dependency: depend on a Factory that can create a Database
	implicit val dbFactory: Factory[Database]
	
	// use that abstract factory to make the database
	val db = make[Database]
	
	trait Database {
		def init(host: String): Unit
	}	
}

trait UseMysql extends MyDependencies {
  // supply the right factory
	implicit object dbFactory extends Factory[MysqlDatabase] {
	  	def make = new MysqlDatabase
	}
	
	class MysqlDatabase extends Database {
		def init(host: String) = println("mysql init "+host)
	}
}

trait UsePostgres extends MyDependencies {
	implicit object dbFactory extends Factory[PgsqlDatabase] {
	  	def make = new PgsqlDatabase
	}
	
	class PgsqlDatabase extends Database {
		def init(host: String) = println("pgsql init "+host)
	}
}

// application with abstract dependencies
trait MyApplication extends MyDependencies with Application {
	db.init("foo")
}

// make dependencies concrete: use MySQL
object applicationMYSQL extends MyApplication with UseMysql

// make dependencies concrete: use Postgres
object applicationPostgres extends MyApplication with UsePostgres

